Agroforestry

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(readxl)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.4
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 3.4.3
library(MASS)
library(jpeg)
library(grid)


img <- readJPEG(file.path('..','DATA','CACAO_PLATANO_4_v2.jpg'))
g <- rasterGrob(img, width=unit(1,"npc"), height=unit(1,"npc"), interpolate = FALSE)


DATA_CO2_EMISSIONS <- read_excel(file.path('..','DATA','DATOS_AGROFORESTRY_CONGRESS.xlsx'))
str(DATA_CO2_EMISSIONS)
## Classes 'tbl_df', 'tbl' and 'data.frame':    42 obs. of  10 variables:
##  $ Tiempo   : num  0 1 2 3 4 5 6 7 8 9 ...
##  $ Carbono  : num  52.1 51 49.9 48.8 47.8 ...
##  $ SE_C     : num  8.54 8.26 7.88 7.52 7.24 ...
##  $ SE_C_MAX : num  60.6 59.2 57.8 56.4 55 ...
##  $ SE_C_MIN : num  43.6 42.7 42 41.3 40.5 ...
##  $ Densidad : num  0.776 0.789 0.802 0.815 0.829 ...
##  $ SE_Den   : num  0.0892 0.0907 0.0922 0.0937 0.0953 ...
##  $ SE_D_MAX : num  0.865 0.879 0.894 0.909 0.924 ...
##  $ SE_D_MIN : num  0.686 0.698 0.71 0.721 0.733 ...
##  $ Cobertura: chr  "Degraded pasture" "Degraded pasture" "Degraded pasture" "Degraded pasture" ...
p <- ggplot(data=DATA_CO2_EMISSIONS, aes(x = Tiempo)) + 
  annotation_custom(g, -Inf, Inf, -Inf, Inf)  
p <- p + geom_line(aes(y = Carbono, colour = "Carbon"), size = 1.5) +
  geom_ribbon(aes(ymin=SE_C_MIN, ymax=SE_C_MAX), alpha=0.6, fill="salmon1") +
  theme(axis.text.x = element_text(colour="black",size=16)) +
  theme(axis.text.y = element_text(colour="black",size=16)) +
  theme(axis.title.y = element_text(colour="black",size=18)) +
  theme(axis.title.x = element_text(colour="black",size=18)) +
  ylab(bquote('SOC (Mg C ' ~ha^-1~')')) +
  xlab(bquote('Time (yr)')) +
  geom_vline(aes(xintercept=30), size=1, colour="#BB0000", linetype="dashed") +
  theme(legend.position = c(0.36, 0.85)) +
  theme(legend.title=element_blank()) +
  theme(legend.text = element_text(colour="black",size=16)) +
  scale_colour_discrete(name  ="Colour",
                        breaks=c("Carbon", "Densidad"),
                        labels=c("SOC", "Bulk density"))
  p <- p + geom_line(aes(y = Densidad*20, colour = "Densidad"), size = 1.5) + 
  geom_ribbon(aes(ymin=SE_D_MIN*20, ymax=SE_D_MAX*20), alpha=0.6, fill="aquamarine3")
p <- p + scale_y_continuous(sec.axis = sec_axis(~./20, name = 'Bulk density (g ' ~cm^-3~')'))

p1 <- p + annotate("text", x = 13.8, y = 2.5, label = "Forest-to-pasture conversion and pasture degradation", size=6)
p1

p2 <- p1 + annotate("text", x = 37, y = 2.5, label = "Agroforestry establishment", size=6)
p2

p3 <- p2 + annotate("segment", x = 0, xend = 29.7, y = 0, yend = 0, colour = "purple", size=3, alpha=0.6, arrow=arrow())
p3

p4 <- p3 + annotate("segment", x = 30.3, xend = 42, y = 0, yend = 0, colour = "blue", size=3, alpha=0.6, arrow=arrow())
p4

  jpeg(file = file.path('..','RESULTS','AGROFORESTRY_CONGRESS_2.jpeg'), width = 1600, height = 1000, res = 150)
  
  p4
  
dev.off()
## png 
##   2

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.